package com.fly.repository.impl;

import com.fly.repository.ChatHistoryRepository;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class InMemoryChatHistoryRepository implements ChatHistoryRepository {

    private final Map<String,List<String>> chatHistoryMap = new HashMap<>();

    @Override
    public void save(String type, String chatId) {
        List<String> strings = chatHistoryMap.computeIfAbsent(type, k -> new ArrayList<>());
        if(strings.contains(chatId)) {
            return;
        }
        strings.add(chatId);
    }

    @Override
    public List<String> getChatIds(String type) {
        return chatHistoryMap.getOrDefault(type, List.of());
    }
}
